import trinity
import blue
from actorfactory.ActorFactory import RegisterFactory
from actorfactory.ActorFactory import BaseActorFactory
AVATAR = 'AVATAR'

class AvatarFactory(BaseActorFactory):

    def __init__(self):
        BaseActorFactory.__init__(self)



    def Register(self, factoryList):
        factoryList[AVATAR] = self



    def CreateObject(self, template, vPos, vForward, vNorm, properties):
        if (template.GetClassType() == AVATAR):
            avatarResPath = str(blue.rot.FilenameToPath(template.GetRes()))
            avatar = trinity.Load(avatarResPath)
            avatar.translation.SetXYZ(vPos.x, vPos.y, vPos.z)
            self.HandleProperties(avatar, properties)
            return avatar



    def AddToScene(self, scene, obj, template):
        if (template.GetClassType() == AVATAR):
            scene.city.AddAvatarToScene(obj)
            return True
        else:
            return False



    def IsSelfCleaning(self):
        return True



    def RemoveFromScene(self, scene, obj, template):
        if (template.GetClassType() == AVATAR):
            scene.city.RemoveAvatarFromScene(obj)
            return True
        else:
            return False



RegisterFactory(AvatarFactory())

